<template>
	<view>
		<view class="shopping_content">
			<!-- 没有商品 Object.keys(this.album).length-->
			<view class="shopping_content_nothing" v-if="goodsItems.length == 0">
				<text>没有商品</text>
			</view>
			<view class="shopping_content_goods" v-if="goodsItems.length > 0">
				<view class="select_all">
					<evan-checkbox v-model="checked" primaryColor="#795C43"><text>全选</text></evan-checkbox>
				</view>
				<view class="goods_list" v-for="(item,index) in goodsItems" :key="item.index">
					<uni-swipe-action>
						<uni-swipe-action-item :right-options="options" @click="onClick($event,index)" @change="change">
							<view class="list_box">
								<view class="goods_btn">
									<evan-checkbox v-model="checked" primaryColor="#795C43">
									</evan-checkbox>
								</view>
								<view class="goods_info_content">
									<view class="goods_image">
										<image :src="item.src" mode="widthFix"></image>
									</view>
									<view class="goods_info">
										<view class="goods_info_title">
											{{item.title}}
										</view>
										<text class="goods_info_text">{{item.text}}</text>
										<view class="goods_info_money">
											<text class="goods_info_money_left">￥{{item.money}}</text>
											<view class="goods_info_money_right">
												<FontAwesome class="fa_icon" type="fas fa-minus"
													@click="count(false,index)">
												</FontAwesome>
												<text>{{item.num}}</text>
												<FontAwesome class="fa_icon" type="fas fa-plus"
													@click="count(true,index)">
												</FontAwesome>
											</view>
										</view>
									</view>
								</view>
							</view>

						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
				<view class="goods_count">
					<view class="goods_count_content">
						<view class="goods_count_money">
							合计:
							<text>￥{{settlement.money}}</text>
						</view>
						<view class="goods_count_btn">
							结算
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import FontAwesome from '../../components/Am-FontAwesome/index.vue';
	import goodsData from '../../static/js/data.js';
	export default {
		data() {
			return {
				goodsItems: goodsData.data.goods_items,
				checked: true,
				settlement: {
					money: 0,
					number: 0
				},
				options: [{
					text: '取消',
					style: {
						backgroundColor: '#795C43'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}]
			}
		},
		components: {
			FontAwesome,
		},
		methods: {
			onClick(e,index) {
				if(e.content.text == "删除"){
					this.goodsItems.splice(index,1)
				}
				this.getNumber()
			},
			change(e, index) {
				console.log(e);
			},
			getNumber() {
				let sum = 0
				this.goodsItems.forEach(v => {
					sum += v.num * parseInt(v.money)
					this.settlement.money = sum.toFixed(2)
					// console.log(this.settlement.money);
				})
			},
			count(bol, index) {
				let shop = this.goodsItems[index]
				console.log(shop);
				if (bol) {
					shop.num++
				} else {
					if (shop.num <= 1) {
						return;
					}
					shop.num--
				}
				this.getNumber()
			}
		},
		onShow() {
			this.getNumber()
		},
		onLoad() {
			// console.log(this.goodsItems);
			this.getNumber()
		}
	}
</script>

<style lang="scss" scoped>
	@import '../../static/css/UiStyle.css';

	.shopping_content {
		.shopping_content_nothing {
			text-align: center;

			text {
				display: block;
				padding: 100rpx 0;
				font-size: 42rpx;
				color: #8f8f8f;
				text-align: center;
			}
		}

		.shopping_content_goods {
			margin-bottom: 120rpx;

			.select_all {
				padding: 20rpx;
			}

			.goods_list {
				// width: 100%;
				// display: flex;
				// justify-content: space-between;
				// align-items: center;
				padding: 20rpx;
				box-sizing: border-box;
				overflow: hidden;

				.list_box {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.goods_btn {
						margin-right: 20rpx;
					}

					.goods_info_content {
						flex: 1;
						display: flex;
						background: #F8F8F8;
						border-radius: 10rpx;

						.goods_image {
							// width: 200rpx;
							// height: 200rpx;
							border-radius: 10rpx;
							overflow: hidden;

							image {
								display: block;
								// width: 100%;
								// height: 100%;
								width: 200rpx;
								height: 200rpx;
							}
						}

						.goods_info {
							flex: 1;
							padding: 0 20rpx;
							box-sizing: border-box;

							.goods_info_title {
								padding: 10rpx 0;
								font-size: 34rpx;
								font-weight: bold;
							}

							.goods_info_text {
								font-size: 24rpx;
								color: #999;
							}

							.goods_info_money {
								margin-top: 30rpx;
								display: flex;
								justify-content: space-between;
								align-items: center;

								.goods_info_money_left {
									font-size: 38rpx;
									font-weight: bold;
									color: $color;
								}

								.goods_info_money_right {
									display: flex;
									align-items: center;

									.fa_icon {
										font-size: 20rpx;
										font-weight: bold;
										color: #000;
										display: block;
										width: 40rpx;
										height: 40rpx;
										line-height: 40rpx;
										background: #ccc;
										text-align: center;
									}

									text {
										font-size: 30rpx;
										font-weight: bold;
										padding: 0 30rpx;
									}
								}
							}
						}
					}
				}


			}

			.goods_count {
				width: 100%;
				position: fixed;
				bottom: var(--window-bottom);
				box-sizing: border-box;
				background: #fff;

				.goods_count_content {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.goods_count_money {
						font-size: 36rpx;
						padding: 20rpx;

						text {
							font-weight: bold;
							margin-left: 20rpx;
						}
					}

					.goods_count_btn {
						padding: 20rpx 40rpx;
						margin: 20rpx;
						font-size: 36rpx;
						color: #fff;
						border-radius: 10rpx;
						background: $color;
					}
				}
			}
		}


	}
</style>
